package com.transpot.controller.order;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.transpot.entry.order.Order;
import com.transpot.entry.order.OrderFee;
import com.transpot.service.order.OrderFeeService;
import com.transpot.service.order.OrderService;
import com.transpot.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/orderFee")
public class OrderFeeController {
    @Autowired
    private OrderFeeService orderFeeService;
    @Autowired
    private OrderService orderService;

    /**
     * 根据订单基本信息主键获取订单的费用信息
     * @param id
     * @return
     */
    @GetMapping("/getOrderFeeById")
    public R getOrderFeeById(Integer id) {
        //创建订单条件查询对象
        LambdaQueryWrapper<Order> orderLambdaQueryWrapper = new LambdaQueryWrapper<>();
        //设置查询条件为订单主键
        orderLambdaQueryWrapper.eq(Order::getBaseId, id);
        //查询订单整合对象
        Order order = orderService.getOne(orderLambdaQueryWrapper);
        //根据订单整和对象中的主键查询订单费用对象
        OrderFee orderFee = orderFeeService.getById(order.getFeeId());
        //返回
        return R.success(orderFee);
    }
}
